﻿using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace OP10.ViewModels
{
    public class LoginViewModel : BindableBase, IDialogAware
    {
        public LoginViewModel()
        {
            model = new List<LevelModel>()
            {
                new LevelModel(){ id=1, level="管理员",password="123"},
                new LevelModel(){ id=2, level="工程师",password="123"},

            };
            SelectedItem = model[0];
        }



        private DelegateCommand _LoginCmd;
        public DelegateCommand LoginCmd =>
            _LoginCmd ?? (_LoginCmd = new DelegateCommand(ExecuteLoginCmd));

        void ExecuteLoginCmd()
        {


            if (Password == SelectedItem.password)
            {

                LoginInfo.IsLogin = true;
                RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
            }
            else
            {
                //MessageBox.Show("密码错误");
                Tips = "密码错误!";
                return;
            }
        }


        private DelegateCommand _ExitCmd;

        public event Action<IDialogResult> RequestClose;

        public DelegateCommand ExitCmd =>
            _ExitCmd ?? (_ExitCmd = new DelegateCommand(ExecuteExitCmd));

        public string Title => "用户登录";

        void ExecuteExitCmd()
        {
            RequestClose?.Invoke(new DialogResult(ButtonResult.None));
        }

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {

        }

        public void OnDialogOpened(IDialogParameters parameters)
        {

        }

        private List<LevelModel> _model;
        public List<LevelModel> model
        {
            get { return _model; }
            set { SetProperty(ref _model, value); }
        }

        private string _Password;
        public string Password
        {
            get { return _Password; }
            set { SetProperty(ref _Password, value); }
        }

        private LevelModel _SelectedItem;
        public LevelModel SelectedItem
        {
            get { return _SelectedItem; }
            set { SetProperty(ref _SelectedItem, value); }
        }
        private string _Tips;
        public string Tips
        {
            get { return _Tips; }
            set { SetProperty(ref _Tips, value); }
        }
    }
}
